package com.yl.ydk.ui.adapter

import android.graphics.Paint
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.yl.ydk.R
import com.yl.ydk.bean.GoodsListBean
import com.yl.ydk.utils.GlideUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder


class HealthyMallAdapter(data: MutableList<GoodsListBean.DataX>?) :
    BaseQuickAdapter<GoodsListBean.DataX, BaseViewHolder>(
        R.layout.item_healthy_mall,
        data
    ) {


    override fun convert(helper: BaseViewHolder?, item: GoodsListBean.DataX?) {

        helper?.let {
            val ivGoods = it.getView<ImageView>(R.id.ivGoods)
            val tvOriginalPrice = it.getView<TextView>(R.id.tvOriginalPrice)
            val rvLabel = it.getView<RecyclerView>(R.id.rvLabel)
            it.setText(R.id.tvName, item?.name)
            it.setText(R.id.tvPrice, "¥ " + item?.price.toString())
            it.setText(R.id.tvOriginalPrice, "¥ " + item?.original_price)
            tvOriginalPrice.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG or Paint.ANTI_ALIAS_FLAG
            GlideUtils.load_e8_bg(mContext, item?.image, ivGoods)

            val adapter = HealthyMallChildAdapter(item?.label?.toMutableList())
            rvLabel.adapter = adapter
            val manager = LinearLayoutManager(mContext)
            manager.orientation = LinearLayoutManager.HORIZONTAL
            rvLabel.layoutManager = manager

            it.itemView.setOnClickListener {
                onItemClick?.onListItemClick(item)
            }

        }
    }

    private var onItemClick: onListItemClick? = null

    interface onListItemClick {
        fun onListItemClick(item: GoodsListBean.DataX?)
    }

    fun onListItemClick(onListItemClick: onListItemClick?) {
        this.onItemClick = onListItemClick
    }

}
